package com.chucang.shucang.common.mq.producer;

import com.chucang.shucang.common.mq.constant.KafkaConstant;
import com.chucang.shucang.common.mq.message.SmsCodeMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;

/**
 * @author flitsneak
 * @email flitsneak@gmail.com
 * @date 2022/9/25 16:36
 * @description 验证码生产者
 */
@Slf4j
@RequiredArgsConstructor
public class SmsCodeProducer {
    private final KafkaTemplate<String, Object> kafkaTemplate;

    /**
     * 发送验证码短信
     *
     * @param mobile  手机号
     * @param smsCode 验证码
     */
    public void sendSmsCode(String mobile, String smsCode) {

        SmsCodeMessage smsCodeMessage = new SmsCodeMessage();
        smsCodeMessage.setMobile(mobile);
        smsCodeMessage.setSmsCode(smsCode);

        kafkaTemplate.send(KafkaConstant.SMS_CODE_TOPIC, smsCodeMessage);
    }
}
